/* 
 * @(#)MimeFilter.java    Created on 5:12:00 PM Dec 27, 2011
 * 
 * Copyright © Longshine Corporation. All rights reserved.
 */
package com.lc.cn.managersys.common;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * <p>
 * Title: 电动汽车智能充换电服务网络运营管理系统_核算_[模块名]
 * </p>
 * <p>
 * Description： [描述该类概要功能]
 * </p>
 * 
 * @author Administrator
 * @version $Revision$
 * @author (latest modification by $Author$)
 * @version since 1.0
 */
public class MimeFilter implements Filter {

	@Override
	public void destroy() {
		// TODO Auto-generated method stub

	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		
		response.setCharacterEncoding("GBK");
		response.setContentType("application/msword");
		File f = new File("E:\\workspace\\manager-sys\\managersys\\WebRoot\\word\\a.doc");
		BufferedInputStream bis = new BufferedInputStream(
				new FileInputStream(f));
		BufferedOutputStream bos = new BufferedOutputStream(response
				.getOutputStream());
		byte buff[] = new byte[4096];
		int bytesRead;
		while (-1 != (bytesRead = bis.read(buff, 0, buff.length)))
			bos.write(buff, 0, bytesRead);
		if (bis != null)
			bis.close();
		if (bos != null) {
			bos.flush();
			bos.close();
		}
	}

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		// TODO Auto-generated method stub

	}
}
